import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;

public class Animal {
	private String species;
	private String name;
	private boolean frinedly;
	private int weight;

	public void writeBinary(OutputStream out) throws IOException {
		DataOutputStream dataOut = new DataOutputStream(out);
		dataOut.writeChars(species);
		dataOut.writeChars(name);
		dataOut.writeBoolean(frinedly);
		dataOut.writeInt(weight);
	}

	public void writetText(Writer out) throws IOException {
		PrintWriter dataOut = new PrintWriter(out);
		dataOut.println(species);
		dataOut.println(name);
		dataOut.println(frinedly);
		dataOut.println(weight);
	}

	public static void main(String[] args) {
		Animal animal1 = new Animal();
		animal1.species = "lion";
		animal1.name = "Scar";
		animal1.frinedly = false;
		animal1.weight = 600;

		try {
			FileOutputStream fileOutputStream = new FileOutputStream(new File(
					"C:/asd/animal.txt"));
			animal1.writeBinary(fileOutputStream);
			fileOutputStream.close();

			FileWriter fileWriter = new FileWriter(new File(
					"C:/asd/animalchar.txt"));
			animal1.writetText(fileWriter);
			fileWriter.close();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
